<?php
require_once("header.php");

if(!$Auth->checkAuth()) // if user isn't logged in
{
    header("location: index.php");
	exit;
}
$uid = $Auth->getLoggedId();

if(isset($_GET['m']))
$m =  safeGet($_GET['m']);	
else
$m = 'current';


switch($m)
{
    case 'current':
	$msql = "SELECT DATE(`date`) as `date1`, SUM(credits) as `credits`, notes FROM earnings_log WHERE uid = '$uid' AND MONTH(`date`) = MONTH(CURDATE()) AND YEAR(`date`) = YEAR(CURDATE()) GROUP BY DATE(`date`)";
	break;
	
	case 'last':
	$msql = "SELECT DATE(`date`) as `date1`, SUM(credits) as `credits`, notes FROM earnings_log WHERE uid = '$uid' AND MONTH(`date`) = MONTH(CURDATE())-1 AND YEAR(`date`) = YEAR(CURDATE()) GROUP BY DATE(`date`)";
	break;

}

$que = mysql_query($msql);

if(mysql_num_rows($que))
{

	$data = "['Date', 'Earnings'],";
	while($r = mysql_fetch_object($que))
	{
	    $credits = $r->credits;
		$notes = $r->notes;	
		$date = date('d',strtotime($r->date1));
		$_tmonth = date('F',strtotime($r->date1));
		$_tyear = date('Y',strtotime($r->date1));
  	    $data .= "['$date', $credits],";	

	}
	
	$data = substr($data, 0, -1);
	$template->assign('data', $data);
}
$template->assign('m', $m);
$template->assign('month', $_tmonth);
$template->assign('year', $_tyear);

$template->display('overview_graph.tpl.php');


?>